import React, {Component} from 'react';
import { Modal} from 'antd';
import PropTypes from 'prop-types';
import '../../assets/stylus/com/dataentry/treeTransfer.styl';
import '../../assets/stylus/com/feedback/modal.styl';


class scModal extends Component {

    constructor (props) {
        super();
        this.props = props;
    }

    state = {
        visible: false,
        tipVisible: false
    }

    showModal (v) {
        this.setState({
            visible: v.modalVisible,
            width: v.width
        });
        this.params = v.param;
    }

    handleOk (e) {
      this.setState({
        visible: !1
      });
      this.props.handle && this.props.handle(this.params);
    }

    handleCancel (e) {
        this.setState({
          visible: !1
        });
      this.props.cancel && this.props.cancel();
    }

  componentWillReceiveProps (nextProps) {
        this.showModal(nextProps);
    }

    render() {
        return (
                <Modal
                    width={this.state.width}
                    title={this.props.modalTitle}
                    visible={this.state.visible}
                    onOk={this.handleOk.bind(this)}
                    onCancel={this.handleCancel.bind(this)}
                    cancelText="取消"
                    okText="确定"
                    wrapClassName="vertical-center-modal"
                    footer={this.props.footer}
                    confirmLoading={this.props.confirmLoading}
                >
                    {this.props.modalContent}
                </Modal>
        );
    }
}

export default scModal;

scModal.propsType = {
    width: PropTypes.number,
    modalVisible: PropTypes.bool,
    modalTitle: PropTypes.string,
    modalContent: PropTypes.object,
    handle: PropTypes.func,
    cancel: PropTypes.func,
    param: PropTypes.object,
    footer: PropTypes.object,
    confirmLoading: PropTypes.bool
}